package com.tarena.lbs.basic.web.dao.repository.impl;


import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.tarena.lbs.basic.web.dao.mapper.UserTagsMapper;
import com.tarena.lbs.basic.web.dao.repository.UserTagsRepository;
import com.tarena.lbs.pojo.basic.dos.UserTagsDO;
import com.tarena.lbs.pojo.basic.param.UserTagsParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Repository
public class UserTagsRepositoryImpl  implements UserTagsRepository {
    @Autowired
    private UserTagsMapper userTagsMapper;

    @Override
    public void deleteUserTags(Integer userId) {
        log.debug("删除标签用户Id UserId={}",userId);
        userTagsMapper.deleteTagsById(userId);
    }

    @Override
    public void batchInsertUserTags(List<UserTagsParam> userTags) {
        log.debug("批量插入用户标签入参 userTags:{}",userTags);
        if (CollectionUtils.isNotEmpty(userTags)){
            List<UserTagsDO> dos = userTags.stream().map(userTag -> {
                UserTagsDO uDO = new UserTagsDO();
                uDO.setUserId(userTag.getUserId());
                uDO.setTagId(Integer.valueOf(userTag.getTagIds()));
                return uDO;
            }).collect(Collectors.toList());
            userTagsMapper.batchInsert(dos);
        }
    }
}
